//
//  HHDetailMoneyViewController.m
//  HHBroker
//
//  Created by He Wei on 10/19/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "HHDetailMoneyViewController.h"
#import "HttpRequestManager.h"
#import "HHMoneyDetailReform.h"

@interface HHDetailMoneyViewController ()

@end

@implementation HHDetailMoneyViewController

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Life Cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"成单详情";
    [self prepareData];
}

#pragma mark - Delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseCell = @"reuseCell";
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseCell];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseCell];
            cell.textLabel.textColor = UIColorFromRGB(0x999999);
            cell.textLabel.font = [UIFont systemFontOfSize:13];
            cell.detailTextLabel.textColor = UIColorFromRGB(0x5d5d5d);
            cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
        }
        NSDictionary *dic = self.dataArray[indexPath.row];
        cell.textLabel.text = [dic objectForKey:@"title"];
        cell.detailTextLabel.text = [dic objectForKey:@"value"];
        return cell;
    }
    return nil;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 200, 14)];
    NSString *string = @"详情";
    if (self.model.type == JYContractTypeSuccessBySales) {
        string = @"跟进成单详情";
    }
    if (self.model.type == JYContractTypeSuccessBySelf) {
        string = @"约见成单详情";
    }
    if (self.model.type == JYContractTypeFail) {
        string = @"退款详情";
    }
    label.text = string;
    label.textColor = UIColorFromRGB(0x2d2d2d);
    [view addSubview:label];
    return view;
}

#pragma mark - Setter && Getter

- (void)prepareData
{
    MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString *urlString = [NSString stringWithFormat:@"%@&com_id=%@&type=%@", KUrlDetailMoney, self.model.Id, @(self.model.type)];
    [HttpRequestManager getWithUrlString:urlString success:^(id response) {
        [hub hide:YES];
        NSInteger code = [[response objectForKey:@"code"] integerValue];
        if (code == 1) {
            id detail = [response objectForKey:@"detail"];
            [self.dataArray addObjectsFromArray:[HHMoneyDetailReform reformDataWithRespone:detail type:self.model.type]];
        }
    
    }failure:^(NSError *error) {
        hub.mode = MBProgressHUDModeText;
        hub.labelText = @"网络有点问题";
        [hub hide:YES afterDelay:2];
    
    } cache:NO];

}






























@end
